const tagArray = ["理想主义青年", "双重人格的", "颜控", "义气虾", "颜控", "的", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "的", "吊炸天的", "mmp的", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "理想主义者", "牛皮的", "吊炸天的", "mmp的", "的", "牛皮的", "吊炸天的", "mmp的"]
var util = require('../../../../../utils/util.js')
var _this
const app = getApp()
Page({
  data: {
    initTagSelectedArray: [],
    initCustomTagSelectedArray: [],
    cutsomTag1: '',
    cutsomTag2: '',
    cutsomTag3: '',
    tagSelectedArray: [],
    customTagSelectedArray: []
  },
  onLoad: function (options) {
    _this = this
    // let data = JSON.parse(options.value).split(',')
    let data = options.value.split(',')
    let customTag = options.customtag == 'null' ? [] : options.customtag.split(',')
    let array = []
    for (let i = 0; i < data.length; i++) {
      array.push(data[i])
    }
    _this.setData({
      initTagSelectedArray: array,
      initCustomTagSelectedArray: customTag
    })
  },
  tagSelectedFinishedHandle: function (e) {
    console.log(e.detail)
    _this.setData({
      tagSelectedArray: e.detail.tagSelectedArray,
      customTagSelectedArray: e.detail.customTagSelectedArray
    })
    //标签已经选择完毕，可以继续下一把
    _this.updateUserInfo()
  },
  updateUserInfo: function () {
    var data = {}
    data.labels3 = _this.data.tagSelectedArray.join()
    if (_this.data.customTagSelectedArray.length > 0) {
      data.otherLabels3 = _this.data.customTagSelectedArray.join()
    }
    util.updateUserInfo(_this.requestDidResponse, _this.requestDidFaild, data)
    wx.showLoading({
      title: '资料保存中...',
    })
  },
  requestDidResponse: (res) => {
    if (res.status == '200') {
      wx.navigateBack({
        delta: 1
      })
    } else {
      wx.showToast({
        title: '保存失败，请重试',
        icon: 'none'
      })
    }
  },
  requestDidFaild: (res) => {
    wx.showToast({
      title: '网络走神了，请稍候再试哦',
      icon: 'none'
    })
  },
  customTagDidClick: function () {
    wx.navigateTo({
      url: '../../infoTagCustom/infoTagCustom',
    })
  },
  addTag: (tag) => {
    console.log(tag)
    _this.setData({
      cutsomTag: tag,
      cutsomTag2: tag
    })
  },
})